package cn.tedu.charging.order.rabbitmq;

import cn.tedu.charging.order.config.RabbitMQConfig;
import cn.tedu.charging.order.pojo.po.OrderMQPO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * rabbit-mq 发送者
 */
@Component
public class RabbitMQOrderProducer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送消息到正常的订单队列
     * 正常的订单队列,没有消费者
     * 消息设置了生存时间
     * 在生存时间过期后,消息会转发到死信队列
     * @param orderMQPO
     */
    public void sendOrder(OrderMQPO orderMQPO) {
        rabbitTemplate.convertAndSend(RabbitMQConfig.ORDER_EXCHANGE,
                RabbitMQConfig.ORDER_ROUTING_KEY,
                orderMQPO);
    }
}
